package com.huawei.appmarket.oobe.app;

import android.app.job.JobInfo.Builder;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.PersistableBundle;
import androidx.annotation.RequiresApi;
import com.huawei.appmarket.service.predownload.jobservice.WlanPeriodicJobService;
import o.dli;
import o.Logger;
import o.ll;

@RequiresApi(api = 21)
public class OOBEQueryIfSupportJobService extends JobService {
    private JobParameters ˎ;

    public static void schedule(Context context, int i, boolean z) {
        if (VERSION.SDK_INT >= 26) {
            String str = "OOBEQueryIfSupportJobService scheduled, fromWhere=" + i;
            long currentTimeMillis = WlanPeriodicJobService.DEFAULT_JOB_PERIODIC - (System.currentTimeMillis() - dli.ˊ(context).getLong("setupwizardFinishedTime", 0));
            PersistableBundle persistableBundle = new PersistableBundle();
            persistableBundle.putInt("fromWhere", i);
            JobScheduler jobScheduler = (JobScheduler) context.getSystemService("jobscheduler");
            Builder extras = new Builder(1003, new ComponentName(context.getPackageName(), OOBEQueryIfSupportJobService.class.getName())).setPersisted(true).setRequiredNetworkType(1).setExtras(persistableBundle);
            if (z && currentTimeMillis > 0) {
                extras.setMinimumLatency(currentTimeMillis);
                str = str + ", latencey=" + currentTimeMillis;
            }
            jobScheduler.schedule(extras.build());
            Logger.ˎ("OOBE", str);
        }
    }

    public static void schedule(Context context, int i) {
        schedule(context, i, true);
    }

    public boolean onStartJob(JobParameters jobParameters) {
        int i;
        this.ˎ = jobParameters;
        if (this.ˎ.getExtras() != null) {
            i = this.ˎ.getExtras().getInt("fromWhere", 0);
        } else {
            i = 0;
        }
        Logger.ˎ("OOBE", "OOBEQueryIfSupportJobService onStartJob, fromWhere=" + i);
        if (dli.ˋ(this) == 2) {
            dli.ˎ(this);
        } else if (dli.ॱˋ(this)) {
            Intent intent = new Intent("com.huawei.appmarket.oobe.ACTION_QUEREY_IF_OOBE_SUPPORT");
            intent.setClass(this, OOBEFlowController.class);
            intent.putExtra("fromWhere", i);
            ll.ˏ(this).ˋ(intent);
        } else {
            if (i == 1) {
                dli.ˊ(this).edit().putBoolean("notificationBlockedBySim", true).commit();
            }
            Logger.ˎ("OOBE", "sim not ready, OOBEQueryIfSupportJobService skipped ");
        }
        return false;
    }

    public boolean onStopJob(JobParameters jobParameters) {
        return true;
    }
}
